package com.example;

import java.util.HashMap;

import android.content.Context;
import android.media.AudioManager;

import com.example.singletones.contextObj;

public class MyAudioManager {

	private static MyAudioManager instance = null;
	private static HashMap<String, Integer> enums = new HashMap<String, Integer>();

	static {
		enums.put("STREAM_RING", AudioManager.STREAM_RING);
		enums.put("STREAM_MUSIC", AudioManager.STREAM_MUSIC);
		enums.put("STREAM_ALARM", AudioManager.STREAM_ALARM);
		enums.put("STREAM_NOTIFICATION", AudioManager.STREAM_NOTIFICATION);
		enums.put("STREAM_SYSTEM", AudioManager.STREAM_SYSTEM);
		enums.put("STREAM_VOICE_CALL", AudioManager.STREAM_VOICE_CALL);
		enums.put("STREAM_DTMF", AudioManager.STREAM_DTMF);
	}

	public static HashMap<String, Integer> getConstants() {
		return enums;
	}

	public static MyAudioManager getInstance() {
		if (instance == null) {
			instance = new MyAudioManager();
			instance.init();
		}
		return instance;
	}

	protected void init() {
		audio = (AudioManager) contextObj.getInstance().getmContext()
				.getSystemService(Context.AUDIO_SERVICE);
	}

	private static AudioManager audio;

	public int setVolume(int stream_type, int volume) {
		if (audio.getStreamMaxVolume(stream_type) < audio
				.getStreamVolume(stream_type) + volume) {
			volume = audio.getStreamMaxVolume(stream_type);
		} else {
			if (audio.getStreamVolume(stream_type) + volume < 0) {
				volume = 0;
			} else {
				volume = audio.getStreamVolume(stream_type) + volume;
			}
		}
		audio.setStreamVolume(stream_type, volume, 0);
		return volume;
	}

	public int getVolume(int stream_type) {
		return audio.getStreamVolume(stream_type);
	}

	public int getStreamMaxVolume(int streamType) {
		return audio.getStreamMaxVolume(streamType);
	}

	public int getStreamVolume(int streamType) {
		return audio.getStreamVolume(streamType);
	}
}
